package com.dek.ssm.ch4.factory;

import java.util.List;
import java.util.Properties;

import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.apache.log4j.Logger;

/**
 *  先调用方法 1 ，然后调用方法 2
 *
 */
public class MyObjectFactory extends DefaultObjectFactory{

	private static final long serialVersionUID = 1L;
	
	Logger logger = Logger.getLogger(MyObjectFactory.class);
	
	private Object temp = null;
	
	@Override
	public void setProperties(Properties properties) {
		super.setProperties(properties);
		logger.info("初始化参数 ：" + properties.toString() + ">");
	}
	
	@Override
	public <T> T create(Class<T> type) {
		T result = super.create(type);
		logger.info("创建对象2：" + result.toString());
		logger.info("是否和上次创建的是同一个对象 ：" + (temp == result) + "");
		return result;
	}
	
	@Override
	public <T> T create(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
		T result = super.create(type, constructorArgTypes, constructorArgs);
		logger.info( "创建对象1： " + result.toString()) ;
		temp = result ;
		return result;
	}
	
	@Override
	public <T> boolean isCollection(Class<T> type) {
		return super.isCollection(type);
	}
	
}
